//
//  SCSelectView.m
//  Assembly
//
//  Created by 葛悦彣 on 2023/11/10.
//

#import "SCSelectView.h"

@interface SCSelectView ()
@property (nonatomic ,strong) NSString * leftStr;

@property (nonatomic ,strong) UILabel * leftLab;
@property (nonatomic ,strong) UILabel * rightLab;
@property (nonatomic ,strong) void(^block)(NSString *str);

@end

@implementation SCSelectView

+ (instancetype)NewViewWithLeftTitle:(NSString *)leftTitle andRightTitle:(NSString *)rightTitle andBlock:(void(^)(NSString *))block {
    SCSelectView * view = [SCSelectView new];
    
    [view setLeftTitle:leftTitle andRightTitle:rightTitle];

    view.block = block;
    
    return view;
}
- (void)setLeftTitle:(NSString *)leftTitle andRightTitle:(NSString *)rightTitle {
   
    UILabel * leftLab = [DTKTool labelWithText:leftTitle andFont:kCFont(17) andTextColor:KcolorHex(@"#1E2425")];
    leftLab.attributedText = [DTKTool AttributedStringWithStr:[NSString stringWithFormat:@"%@*",leftTitle] andNodeColor:KcolorHex(@"#1E2425") andSeledColor:KcolorHex(@"#F14424") andFont:KCFont(17) andPattenr:@"[*]"];
    [self addSubview:leftLab];
    self.leftLab = leftLab;
    leftLab.mas_KLS().mas_KYS();
    [leftLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.offset(kwt(15));
    }];
    
    UIImageView * rightImg = kimageView(@"opening_return2");
    [self addSubview:rightImg];
    [rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.offset(kwt(-15));
        make.width.height.offset(kwt(17));
    }];
    
    UILabel * rightLab = [DTKTool labelWithText:@"请选择" andFont:kFont(17) andTextColor:KcolorHex(@"#878D8F")];
    [self addSubview:rightLab];
    self.rightLab = rightLab;
    rightLab.textAlignment = NSTextAlignmentRight;
    [rightLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.offset(kwt(-40));
        make.left.equalTo(leftLab.mas_right).offset(kwt(10));
    }];
    self.leftStr = leftTitle;
    self.rightStr = rightTitle;
    MJWeakSelf
    self.addClickBlock(^(){
        [weakSelf viewClick];
    });
}

- (void)setRightStr:(NSString *)rightStr {
    _rightStr = rightStr;
    if(rightStr.length > 0){
        self.rightLab.text = rightStr;
        self.rightLab.textColor = KcolorHex(@"#1E2425");
    } else {
        self.rightLab.text = @"请选择";
        self.rightLab.textColor = KcolorHex(@"#878D8F");

    }
}
- (void)viewClick{
    if(self.block){
        self.block(self.leftStr);
    }
}

@end
